/**
 * 
 */
package patterns.observer;

import java.util.ArrayList;

/**
 * @author gabriel
 *
 */
public class ConcreteSubject implements Subject {

	private ArrayList<Observer> observers;
	
	
	/**
	 * 
	 */
	public ConcreteSubject() {
		observers = new ArrayList<Observer>();
	}

	/* (non-Javadoc)
	 * @see patterns.observer.Subject#registerObserver(patterns.observer.Observer)
	 */
	@Override
	public void registerObserver(Observer obs) {
		observers.add(obs);
	}

	/* (non-Javadoc)
	 * @see patterns.observer.Subject#removeObserver(patterns.observer.Observer)
	 */
	@Override
	public void removeObserver(Observer obs) {
		int i = observers.indexOf(obs);
		if (i >= 0){
			observers.remove(i);
		}
	}

	/* (non-Javadoc)
	 * @see patterns.observer.Subject#notifyObservers()
	 */
	@Override
	public void notifyObservers() {
		for(Observer obs : observers){
			obs.update();
		}

	}

	@Override
	public void notififyObservers(String name) {
		for(Observer obs : observers){
			obs.update(name);
		}
		
	}

}
